﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Text;
using System.IO;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using Rison.Web.Common;
using Rison.BusinessFacade.Helper;
using Rison.BusinessFacade.Common;
using Rison.BusinessFacade.Entity.NRBZ;
using Rison.BusinessFacade.Facade.NRBZ;
using Rison.DataAccess.Common;

namespace Rison.Web.NRBZ
{
    public partial class ZwzglDetail : NrfbPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        public override void LoadInformation(DataRow dr)
        {
            if (dr != null)
            {
                rblIfxxfbsh.SelectedValue = dr["Ifxxfbsh"].ToString() == "是" ? "是" : "否";
                rblIfxxaqbz.SelectedValue = dr["Ifxxaqbz"].ToString() == "是" ? "是" : "否";

                NrbzFacade facade = new NrbzFacade();
                DataSet ds = facade.LoadAttachement(NrbzId, 4);
                DataList1.DataSource = ds.Tables[0];
                DataList1.DataBind();

                ds = facade.LoadAttachement(NrbzId, 5);
                DataList2.DataSource = ds.Tables[0];
                DataList2.DataBind();

            }
           
        }

        public override long SaveInformation()
        {
            NrbzFacade facade = new NrbzFacade();
            List<DataField> l = new List<DataField>();

            int returnValue = 0;

            l.Add(new DataField("Ifxxfbsh", rblIfxxfbsh.SelectedValue));
            l.Add(new DataField("Ifxxaqbz", rblIfxxaqbz.SelectedValue));

            returnValue = facade.updateValue(l, NrbzId);

            //上传控件
            //this.FileUpload1.btnUpload_Click();
            //this.FileUpload2.btnUpload_Click();
            //uploadFile(this.fileUpload1,1);
            //uploadFile(this.fileUpload2,2);
            uploadFile();
           

            return returnValue;
        }

        public string uploadFile()
        {
            string val = Request.Params["fileUploader4_hdnFileVal"];
            string val1 = Request.Params["fileUploader5_hdnFileVal"];
            string del = "";
            List<SysAttachment> _attachments = new List<SysAttachment>();
            int returnValue = -1;

            NrbzFacade facade = new NrbzFacade();
            if (!string.IsNullOrEmpty(val))
            {
                _attachments = NewUpload(val);
                returnValue = facade.InsertAttachment(NrbzId, 4, _attachments);
               
            }

            del = Request.Params["fileUploader4_del"];
            if(!string.IsNullOrEmpty(del))
            returnValue = facade.DeleteAttachment(del);

            if (!string.IsNullOrEmpty(val1))
            {
                _attachments = NewUpload(val1);
                returnValue = facade.InsertAttachment(NrbzId, 5, _attachments);
               
            }

            del = Request.Params["fileUploader5_del"];
            if (!string.IsNullOrEmpty(del))
            returnValue = facade.DeleteAttachment(del);

            if (returnValue < 0)
            {
                return "文件上传成功，保存有误！";
            }

            return "";
        }

        


        //public string uploadFile(HtmlInputFile fileUpload,int type)
        //{
        //    //检查上传文件不为空
        //    if (fileUpload.PostedFile.ContentLength > 0)
        //    {
        //        FileUploader uploader = new FileUploader();
        //        uploader.SetSizeUnit(FileSize.MegaByte);
        //        int LimitedSize=5; //大小
        //        List<string> AllowedExtensionList =new List<string>(); //后缀名
        //        AllowedExtensionList.Add(".doc");

        //        string UploadFolder = "";   //文件路径

        //        //路径
        //        uploader.FileUploadFolder = (string.IsNullOrEmpty(UploadFolder)) ? GlobalParams.Instance.AttachmentUploadUrl : UploadFolder;

        //        //判断文件大小和后缀名
        //        if (uploader.Upload(fileUpload.PostedFile, (LimitedSize > 0) ? LimitedSize : GlobalParams.Instance.maxAttachmentSize, AllowedExtensionList) == false)
        //        {
        //            return "文件上传失败！";

        //        }
        //        else
        //        {
        //            List<SysAttachment> _attachments = new List<SysAttachment>();
        //            SysAttachment att = new SysAttachment();
        //            att.FileName = uploader.OriginalName;
        //            att.FilePath = uploader.UploadedPath;
        //            att.FileSize = uploader.FileLength;
        //            att.Extension = uploader.Extension;
        //            att.ContentType = uploader.ContentType;

        //            _attachments.Add(att);

        //            NrbzFacade facade = new NrbzFacade();
        //            int returnValue = facade.InsertAttachment(NrbzId,type, _attachments);

        //            if (returnValue < 0)
        //            {
        //                return "文件上传成功，保存有误！";
        //            }
        //        }

        //    }
        //    return "";
        //}

        

       
    }
}